#ifndef _WX_FILEBACK_H__
#define _WX_FILEBACK_H__

#include "wx/defs.h"

#if wxUSE_FILESYSTEM

#include "wx/stream.h"

class wxBackingFile {
  public:
    enum { DefaultBufSize = 16384 };
    wxBackingFile( wxInputStream *stream,size_t bufsize = DefaultBufSize,const wxString& prefix = wxT( "wxbf" ) );
    wxBackingFile() : m_impl( NULL ) { }
    ~wxBackingFile();
    wxBackingFile( const wxBackingFile& backer );
    wxBackingFile& operator=( const wxBackingFile& backer );
    operator bool() const { return m_impl != NULL; }
  private:
    class wxBackingFileImpl *m_impl;
    friend class wxBackedInputStream;
};

class wxBackedInputStream : public wxInputStream {
  public:
    wxBackedInputStream( const wxBackingFile& backer );
    wxFileOffset GetLength() const;
    wxFileOffset FindLength() const;
    bool IsSeekable() const { return true; }
  protected:
    size_t OnSysRead( void *buffer, size_t size );
    wxFileOffset OnSysSeek( wxFileOffset pos, wxSeekMode mode );
    wxFileOffset OnSysTell() const;
  private:
    wxBackingFile m_backer;
    wxFileOffset m_pos;
    DECLARE_NO_COPY_CLASS( wxBackedInputStream )
};

#endif // wxUSE_FILESYSTEM

#endif // _WX_FILEBACK_H__
